
/*  
    Configuration may be tree structure, or one flat structure, Flat Stucture is selected
    Support 3 types: bool, int, std::string
*/

#ifndef __MINIUTIL_FRAME_SIMPLEDATAWARE_H__
#define __MINIUTIL_FRAME_SIMPLEDATAWARE_H__

#include <string>
#include <map>

namespace miniutil { namespace frame {
    
    struct SimpleDataWareValue
    {
        static const int VALUE_TYPE_UNKNOWN = 0;
        static const int VALUE_TYPE_BOOL = 1;
        static const int VALUE_TYPE_INT = 2;
        static const int VALUE_TYPE_STR = 3;
        
        SimpleDataWareValue();
        SimpleDataWareValue(bool);
        SimpleDataWareValue(int);
        SimpleDataWareValue(const std::string&);
        SimpleDataWareValue(const char*);
        
        int SetValue(const std::string& vle);
        int SetValue(int vle);
        int SetValue(bool vle);
        //not use enum, since error prone on some embed platform
        int vtype;
        bool bvle;
        int ivle;
        std::string svle;
    };
    
    class SimpleDataWare
    {
        public:
            static SimpleDataWare* GetInstance();
            static void DeleteInstance();
            static SimpleDataWare* pinst;
        public:
            SimpleDataWare();
            ~SimpleDataWare();
            
            int SetValue(std::string key, bool vle);
            int SetValue(std::string key, int vle);
            int SetValue(std::string key, const std::string & vle);
            int SetValue(std::string key, const char* vle);
                
            bool GetBoolValue(std::string);
            int GetIntValue(std::string);
            std::string GetStrValue(std::string);
                
            int ClearKey(std::string);
                
            bool IsKeyAvailable(std::string);
        private:
            std::map<std::string, SimpleDataWareValue> mmallvles;
    };

} }
#endif
